package com.zany.children.service;

import com.zany.children.dao.StudentDao;
import com.zany.children.vo.Class;
import com.zany.children.vo.Student;
import com.zany.login.dao.LoginDao;

import java.util.List;
import java.util.Map;

public class StudentServiceImpl implements StudentService {
    public StudentDao getStudentDao() {
        return studentDao;
    }

    public void setStudentDao(StudentDao studentDao) {
        this.studentDao = studentDao;
    }

    private StudentDao studentDao;

    @Override
    public List<Student> getStudentListPage(Map<String,Object> student) {

        return studentDao.getStudentListPage(student);
    }

    @Override
    public Integer getStudentListPageCount(Map<String,Object> student) {
        return studentDao.getStudentListPageCount(student);
    }


    @Override
    public Long saveStudent(Student student,Long classId) {
        Long stuId = studentDao.saveStudent(student);
        studentDao.saveClassStuRela(classId,stuId,student.getCreater());
        return stuId;
    }


    @Override
    public void updateStudent(Student student) {
        Class clazz = student.getClazz();
        studentDao.updateStudent(student);
        studentDao.deleteClassStuRelaByStuId(student.getId());
        studentDao.saveClassStuRela(clazz.getId(),student.getId(),student.getCreater());

    }


    @Override
    public Student getStudentById(Long id){
        Student student = studentDao.getStudentById(id);
        return student;
    }

    @Override
    public void saveClassStuRela(Long classId, Long stuId, String creater) {
        studentDao.saveClassStuRela(classId,stuId,creater);
    }

    @Override
    public void deleteStudentById(Long stuId) {
        studentDao.deleteClassStuRelaByStuId(stuId);
        studentDao.deleteStudentById(stuId);
    }
}
